<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends SMB_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->library('data');
		$this->load->helper('ext_form');
	}
	
	public function index() {
		$this->_get_userinfo();
		
		$this->load->helper('table');
		
		$this->_load_common_header();
		$this->_load_common_navigation();
		$this->_load_common_sidebar(get_user_sidebar($this->userinfo['role'], 'studentlist'));
		$params = array(
			'majors' => $this->data->list_major(),
			'years' => $this->data->list_year()
		);
		
		if ($this->input->get('search') == FALSE) {
			$limit = $this->data->count_student();
			$params['students'] = $this->data->search_student('0', $limit);
			$params['title'] = 'Daftar Semua Mahasiswa';
		} else {
			$name = $this->input->get('name', TRUE);
			$year = $this->input->get('year', TRUE);
			$major = $this->input->get('major', TRUE);
			if ($name == FALSE) {
				$name = '';
			}
			if ($year == FALSE) {
				$year = '';
			}
			if ($major == FALSE) {
				$major = '';
			}
			$limit = $this->data->count_student($name, $year, $major);
			$params['title'] = 'Daftar Hasil Pencarian Mahasiswa';
			$params['students'] = $this->data->search_student('0', $limit, $name, $year, $major);
		}
	
		$params['role'] = $this->userinfo['role'];
		$params['pager'] = get_pager(3);
		$this->load->view('common/student_list', $params);
		$this->_load_common_footer();
	}
}